package com.tools.common.container;

import com.tools.common.object.C;
import com.tools.common.object.Force;
import com.tools.common.object.Note;
import com.tools.common.object.ObjKit;

import java.lang.reflect.Array;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * 数组集合容器操作类的
 * 一些通用方法的封装抽取
 * */
@Note("数组集合容器操作类的一些通用方法的封装抽取")
class RowGenericKit {
    
    RowGenericKit() {}

    @Note("获取可迭代容器内部元素的个数")
    public static int getIterableSize(Iterable iterable) {
        if(iterable == null) return 0;
        if(iterable instanceof Collection) return ((Collection<?>) iterable).size();
        if(iterable instanceof OwnRows) return ((OwnRows<?>) iterable).size();
        return default_getIterableLength(iterable);
    }

    /* ************************************************************************************************************
     *
     *          List 类型
     *
     * ************************************************************************************************************
     * */

    @Note("ArrayList")
    public static <T> ArrayList<T> toArrayList(Object array, C<T> valueType) {
        return toArrayList(array, valueType, (Force) null);
    }


    public static <T> ArrayList<T> toArrayList(Object array, C<T> valueType, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new ArrayList<>();
        int length = Array.getLength(array);
        return (ArrayList<T>) private_asCollection(new ArrayList<>(length), valueType, array, length, force);
    }


    public static <T>ArrayList<T> toArrayList(Object array, C<T> valueType, Comparator<? super T> c) {
        return toArrayList(array, valueType, c, null);
    }

    public static <T>ArrayList<T> toArrayList(Object array, C<T> valueType, Comparator<? super T> c, Force force) {
        ArrayList<T> result = toArrayList(array, valueType, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Object... elements) {
        return toArrayList(valueType, (Force) null, elements);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Force force, Object... elements) {
        if(elements == null || valueType == null) return new ArrayList<>();
        int length = elements.length;
        if(length == 0) return new ArrayList<>();
        return (ArrayList<T>) private_asCollection(new ArrayList<>(length), valueType, elements, force);
    }


    @Note("将数组内的元素转为指定泛型的 ArrayList 集合，并对集合做排序。该方法的 elements 主要为了一个数组内可装不同类型的元素")
    public static <T>ArrayList<T> toArrayList(C<T> valueType, Comparator<? super T> c, Object... elements) {
        return toArrayList(valueType, c, null, elements);
    }


    public static <T>ArrayList<T> toArrayList(C<T> valueType, Comparator<? super T> c, Force force, Object... elements) {
        ArrayList<T> result = toArrayList(valueType, force, elements);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Collection elements) {
        return toArrayList(valueType, elements, (Force) null);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Collection elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new ArrayList<>();
        return (ArrayList<T>) private_asCollection(new ArrayList<>(elements.size()), valueType, elements, force);
    }


    public static <T>ArrayList<T> toArrayList(C<T> valueType, Collection elements, Comparator<? super T> c) {
        return toArrayList(valueType, elements, c, null);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Collection elements, Comparator<? super T> c, Force force) {
        ArrayList<T> result = toArrayList(valueType, elements, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, OwnRows elements) {
        return toArrayList(valueType, elements, (Force) null);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, OwnRows elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new ArrayList<>();
        return (ArrayList<T>) private_asCollection(new ArrayList<>(elements.size()), valueType, elements, null);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, OwnRows elements, Comparator<? super T> c) {
        return toArrayList(valueType, elements, c, null);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, OwnRows elements, Comparator<? super T> c, Force force) {
        ArrayList<T> result = toArrayList(valueType, elements, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Iterable elements) {
        return toArrayList(valueType, elements, (Force) null);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Iterable elements, Force force) {
        if(elements == null || valueType == null) return new ArrayList<>();
        return (ArrayList<T>) private_asCollection(new ArrayList<>(default_getIterableLength(elements)), valueType, elements, force);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Iterable elements, Comparator<? super T> c) {
        return toArrayList(valueType, elements, c, null);
    }

    public static <T>ArrayList<T> toArrayList(C<T> valueType, Iterable elements, Comparator<? super T> c, Force force) {
        ArrayList<T> result = toArrayList(valueType, elements, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }


    @Note("LinkedList")
    public static <T> LinkedList<T> toLinkedList(Object array, C<T> valueType) {
        return toLinkedList(array, valueType, (Force) null);
    }

    public static <T> LinkedList<T> toLinkedList(Object array, C<T> valueType, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new LinkedList<>();
        return (LinkedList<T>) private_asCollection(new LinkedList<>(), valueType, array, Array.getLength(array), force);
    }

    public static <T>LinkedList<T> toLinkedList(Object array, C<T> valueType, Comparator<? super T> c) {
        return toLinkedList(array, valueType, c, null);
    }

    public static <T>LinkedList<T> toLinkedList(Object array, C<T> valueType, Comparator<? super T> c, Force force) {
        LinkedList<T> result = toLinkedList(array, valueType, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Object... elements) {
        return toLinkedList(valueType, (Force) null, elements);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Force force, Object... elements) {
        if(elements == null || elements.length == 0 || valueType == null) return new LinkedList<>();
        return (LinkedList<T>) private_asCollection(new LinkedList<>(), valueType, elements, force);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Comparator<? super T> c, Object... elements) {
        return toLinkedList(valueType, c, null, elements);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Comparator<? super T> c, Force force, Object... elements) {
        LinkedList<T> result = toLinkedList(valueType, elements, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Collection elements) {
        return toLinkedList(valueType, elements, (Force) null);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Collection elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new LinkedList<>();
        return (LinkedList<T>) private_asCollection(new LinkedList<>(), valueType, elements, force);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Collection elements, Comparator<? super T> c) {
        return toLinkedList(valueType, elements, c, null);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Collection elements, Comparator<? super T> c, Force force) {
        LinkedList<T> result = toLinkedList(valueType, elements, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, OwnRows elements) {
        return toLinkedList(valueType, elements, (Force) null);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, OwnRows elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new LinkedList<>();
        return (LinkedList<T>) private_asCollection(new LinkedList<>(), valueType, elements, force);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, OwnRows elements, Comparator<? super T> c) {
        return toLinkedList(valueType, elements, c, null);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, OwnRows elements, Comparator<? super T> c, Force force) {
        LinkedList<T> result = toLinkedList(valueType, elements, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Iterable elements) {
        return toLinkedList(valueType, elements, (Force) null);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Iterable elements, Force force) {
        if(elements == null || valueType == null) return new LinkedList<>();
        return (LinkedList<T>) private_asCollection(new LinkedList<>(), valueType, elements, force);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Iterable elements, Comparator<? super T> c) {
        return toLinkedList(valueType, elements, c, null);
    }

    public static <T>LinkedList<T> toLinkedList(C<T> valueType, Iterable elements, Comparator<? super T> c, Force force) {
        LinkedList<T> result = toLinkedList(valueType, elements, force);
        if(result.isEmpty()) return result;
        result.sort(c);
        return result;
    }

    @Note("CopyOnWriteArrayList")
    public static <T> CopyOnWriteArrayList<T> toCopyOnWriteArrayList(Object array, C<T> valueType) {
        return toCopyOnWriteArrayList(array, valueType, null, null);
    }

    public static <T> CopyOnWriteArrayList<T> toCopyOnWriteArrayList(Object array, C<T> valueType, Force force) {
        return toCopyOnWriteArrayList(array, valueType, null, force);
    }

    public static <T> CopyOnWriteArrayList<T> toCopyOnWriteArrayList(Object array, C<T> valueType, Comparator<? super T> c) {
        return toCopyOnWriteArrayList(array, valueType, c, null);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(Object array, C<T> valueType, Comparator<? super T> c, Force force) {
        ArrayList<T> ts = toArrayList(array, valueType, c, force);
        if(ts.isEmpty()) return new CopyOnWriteArrayList<>();
        return new CopyOnWriteArrayList<>(ts);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Object... elements) {
        return toCopyOnWriteArrayList(valueType, null, null, elements);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Force force, Object... elements) {
        return toCopyOnWriteArrayList(valueType, null, force, elements);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Comparator<? super T> c, Object... elements) {
        return toCopyOnWriteArrayList(valueType, c, null, elements);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Comparator<? super T> c, Force force, Object... elements) {
        ArrayList<T> ts = toArrayList(valueType, c, force, elements);
        if(ts.isEmpty()) return new CopyOnWriteArrayList<>();
        return new CopyOnWriteArrayList<>(ts);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Collection elements) {
        return toCopyOnWriteArrayList(valueType, elements, null, null);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Collection elements, Force force) {
        return toCopyOnWriteArrayList(valueType, elements, null, force);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Collection elements, Comparator<? super T> c) {
        return toCopyOnWriteArrayList(valueType, elements, c, null);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Collection elements, Comparator<? super T> c, Force force) {
        ArrayList<T> ts = toArrayList(valueType, elements, c, force);
        if(ts.isEmpty()) return new CopyOnWriteArrayList<>();
        return new CopyOnWriteArrayList<>(ts);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, OwnRows elements) {
        return toCopyOnWriteArrayList(valueType, elements, null, null);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, OwnRows elements, Force force) {
        return toCopyOnWriteArrayList(valueType, elements, null, force);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, OwnRows elements, Comparator<? super T> c) {
        return toCopyOnWriteArrayList(valueType, elements, c, null);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, OwnRows elements, Comparator<? super T> c, Force force) {
        ArrayList<T> ts = toArrayList(valueType, elements, c, force);
        if(ts.isEmpty()) return new CopyOnWriteArrayList<>();
        return new CopyOnWriteArrayList<>(ts);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Iterable elements) {
        return toCopyOnWriteArrayList(valueType, elements, null, null);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Iterable elements, Force force) {
        return toCopyOnWriteArrayList(valueType, elements, null, force);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Iterable elements, Comparator<? super T> c) {
        return toCopyOnWriteArrayList(valueType, elements, c, null);
    }

    public static <T>CopyOnWriteArrayList<T> toCopyOnWriteArrayList(C<T> valueType, Iterable elements, Comparator<? super T> c, Force force) {
        ArrayList<T> ts = toArrayList(valueType, elements, c, force);
        if(ts.isEmpty()) return new CopyOnWriteArrayList<>();
        return new CopyOnWriteArrayList<>(ts);
    }

    /* ************************************************************************************************************
     *
     *          Set 类型
     *
     * ************************************************************************************************************
     * */

    @Note("HashSet")
    public static <T> HashSet<T> toHashSet(Object array, C<T> valueType) {
        return toHashSet(array, valueType, null);
    }

    public static <T> HashSet<T> toHashSet(Object array, C<T> valueType, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new HashSet<>();
        int length = Array.getLength(array);
        return (HashSet<T>) private_asCollection(new HashSet<>(default_calcSize(length)), valueType, array, length, force);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, Object... elements) {
        return toHashSet(valueType, null, elements);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, Force force, Object... elements) {
        if(elements == null || valueType == null) return new HashSet<>();
        int length = elements.length;
        if(length == 0) return new HashSet<>();
        return (HashSet<T>) private_asCollection(new HashSet<>(default_calcSize(length)), valueType, elements, force);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, Collection elements) {
        return toHashSet(valueType, elements, null);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, Collection elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new HashSet<>();
        return (HashSet<T>) private_asCollection(new HashSet<>(default_calcSize(elements.size())), valueType, elements, force);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, OwnRows elements) {
        return toHashSet(valueType, elements, null);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, OwnRows elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new HashSet<>();
        return (HashSet<T>) private_asCollection(new HashSet<>(default_calcSize(elements.size())), valueType, elements, force);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, Iterable elements) {
        return toHashSet(valueType, elements, null);
    }

    public static <T>HashSet<T> toHashSet(C<T> valueType, Iterable elements, Force force) {
        if(elements == null || valueType == null) return new HashSet<>();
        return (HashSet<T>) private_asCollection(new HashSet<>(default_calcSize(default_getIterableLength(elements))), valueType, elements, force);
    }

    @Note("LinkedHashSet")
    public static <T>LinkedHashSet<T> toLinkedHashSet(Object array, C<T> valueType) {
        return toLinkedHashSet(array, valueType, null);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(Object array, C<T> valueType, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new LinkedHashSet<>();
        int length = Array.getLength(array);
        return (LinkedHashSet<T>) private_asCollection(new LinkedHashSet<>(default_calcSize(length)), valueType, array, length, force);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, Object... elements) {
        return toLinkedHashSet(valueType, null, elements);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, Force force, Object... elements) {
        if(elements == null || valueType == null) return new LinkedHashSet<>();
        int length = elements.length;
        if(length == 0) return new LinkedHashSet<>();
        return (LinkedHashSet<T>) private_asCollection(new LinkedHashSet<>(default_calcSize(length)), valueType, elements, force);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, Collection elements) {
        return toLinkedHashSet(valueType, elements, null);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, Collection elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new LinkedHashSet<>();
        return (LinkedHashSet<T>) private_asCollection(new LinkedHashSet<>(default_calcSize(elements.size())), valueType, elements, force);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, OwnRows elements) {
        return toLinkedHashSet(valueType, elements, null);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, OwnRows elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new LinkedHashSet<>();
        return (LinkedHashSet<T>) private_asCollection(new LinkedHashSet<>(default_calcSize(elements.size())), valueType, elements, force);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, Iterable elements) {
        return toLinkedHashSet(valueType, elements, null);
    }

    public static <T>LinkedHashSet<T> toLinkedHashSet(C<T> valueType, Iterable elements, Force force) {
        if(elements == null || valueType == null) return new LinkedHashSet<>();
        return (LinkedHashSet<T>) private_asCollection(new LinkedHashSet<>(default_calcSize(default_getIterableLength(elements))), valueType, elements, force);
    }


    @Note("CopyOnWriteArraySet")
    public static <T> CopyOnWriteArraySet<T> toCopyOnWriteArraySet(Object array, C<T> valueType) {
        return toCopyOnWriteArraySet(array, valueType, null);
    }

    public static <T> CopyOnWriteArraySet<T> toCopyOnWriteArraySet(Object array, C<T> valueType, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new CopyOnWriteArraySet<>();
        HashSet<T> ts = toHashSet(array, valueType, force);
        if(ts.isEmpty()) return new CopyOnWriteArraySet<>();
        return new CopyOnWriteArraySet<>(ts);
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, Object... elements) {
        return toCopyOnWriteArraySet(valueType, null, elements);
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, Force force, Object... elements) {
        if(elements == null || elements.length == 0 || valueType == null) return new CopyOnWriteArraySet<>();
        HashSet<T> ts = toHashSet(valueType, elements, force);
        if(ts.isEmpty()) return new CopyOnWriteArraySet<>();
        return new CopyOnWriteArraySet<>(ts);
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, Collection elements) {
        return toCopyOnWriteArraySet(valueType, elements, null);
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, Collection elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new CopyOnWriteArraySet<>();
        HashSet<T> ts = toHashSet(valueType, elements, force);
        if(ts.isEmpty()) return new CopyOnWriteArraySet<>();
        return new CopyOnWriteArraySet<>(ts);
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, OwnRows elements) {
        return toCopyOnWriteArraySet(valueType, elements, null);
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, OwnRows elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new CopyOnWriteArraySet<>();
        HashSet<T> ts = toHashSet(valueType, elements, force);
        if(!ts.isEmpty()) return new CopyOnWriteArraySet<>(ts);
        return new CopyOnWriteArraySet<>();
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, Iterable elements) {
        return toCopyOnWriteArraySet(valueType, elements, null);
    }

    public static <T>CopyOnWriteArraySet<T> toCopyOnWriteArraySet(C<T> valueType, Iterable elements, Force force) {
        if(elements == null || valueType == null) return new CopyOnWriteArraySet<>();
        HashSet<T> ts = toHashSet(valueType, elements, force);
        if(ts.isEmpty()) return new CopyOnWriteArraySet<>();
        return new CopyOnWriteArraySet<>(ts);
    }


    @Note("TreeSet")
    public static <T>TreeSet<T> toTreeSet(Object array, C<T> valueType) {
        return toTreeSet(array, valueType, null, null);
    }

    public static <T>TreeSet<T> toTreeSet(Object array, C<T> valueType, Force force) {
        return toTreeSet(array, valueType, null, force);
    }


    public static <T>TreeSet<T> toTreeSet(Object array, C<T> valueType, Comparator<? super T> c) {
        return toTreeSet(array, valueType, c, null);
    }

    public static <T>TreeSet<T> toTreeSet(Object array, C<T> valueType, Comparator<? super T> c, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new TreeSet<>(c);
        return (TreeSet<T>) private_asCollection(new TreeSet<>(c), valueType, array, Array.getLength(array), force);
    }


    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Object... elements) {
        return toTreeSet(valueType, null, null, elements);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Force force, Object... elements) {
        return toTreeSet(valueType, null, force, elements);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Comparator<? super T> c, Object... elements) {
        return toTreeSet(valueType, c, null, elements);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Comparator<? super T> c, Force force, Object... elements) {
        if(elements == null || valueType == null || elements.length == 0) return new TreeSet<>(c);
        return (TreeSet<T>) private_asCollection(new TreeSet<>(c), valueType, elements, force);
    }


    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Collection elements) {
        return toTreeSet(valueType, elements, null, null);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Collection elements, Force force) {
        return toTreeSet(valueType, elements, null, force);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Collection elements, Comparator<? super T> c) {
        return toTreeSet(valueType, elements, c, null);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Collection elements, Comparator<? super T> c, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new TreeSet<>(c);
        return (TreeSet<T>) private_asCollection(new TreeSet<>(c), valueType, elements, force);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, OwnRows elements) {
        return toTreeSet(valueType, elements, null, null);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, OwnRows elements, Force force) {
        return toTreeSet(valueType, elements, null, force);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, OwnRows elements, Comparator<? super T> c) {
        return toTreeSet(valueType, elements, c, null);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, OwnRows elements, Comparator<? super T> c, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new TreeSet<>(c);
        return (TreeSet<T>) private_asCollection(new TreeSet<>(c), valueType, elements, force);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Iterable elements) {
        return toTreeSet(valueType, elements, null, null);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Iterable elements, Comparator<? super T> c) {
        return toTreeSet(valueType, elements, c, null);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Iterable elements, Force force) {
        return toTreeSet(valueType, elements, null, force);
    }

    public static <T>TreeSet<T> toTreeSet(C<T> valueType, Iterable elements, Comparator<? super T> c, Force force) {
        if(elements == null || valueType == null) return new TreeSet<>(c);
        return (TreeSet<T>) private_asCollection(new TreeSet<>(c), valueType, elements, force);
    }

    @Note("ConcurrentHashSet")
    public static <T> ConcurrentHashSet<T> toConcurrentHashSet(Object array, C<T> valueType) {
        return toConcurrentHashSet(array, valueType, null);
    }

    public static <T> ConcurrentHashSet<T> toConcurrentHashSet(Object array, C<T> valueType, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new ConcurrentHashSet<>();
        int length = Array.getLength(array);
        if(length == 0) return new ConcurrentHashSet<>();
        return (ConcurrentHashSet<T>) private_asCollection(new ConcurrentHashSet<>(length), valueType, array, length, force);
    }

    public static <T>ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, Object... elements) {
        return toConcurrentHashSet(valueType, null, elements);
    }

    public static <T>ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, Force force, Object... elements) {
        if(elements == null || valueType == null) return new ConcurrentHashSet<>();
        int length = elements.length;
        if(length == 0) return new ConcurrentHashSet<>();
        return (ConcurrentHashSet<T>) private_asCollection(new ConcurrentHashSet<>(length), valueType, elements, force);
    }

    public static <T> ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, Collection elements) {
        return toConcurrentHashSet(valueType, elements, null);
    }

    public static <T> ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, Collection elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new ConcurrentHashSet<>();
        return (ConcurrentHashSet<T>) private_asCollection(new ConcurrentHashSet<>(elements.size()), valueType, elements, force);
    }

    public static <T>ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, OwnRows elements) {
        return toConcurrentHashSet(valueType, elements, null);
    }

    public static <T>ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, OwnRows elements, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new ConcurrentHashSet<>();
        return (ConcurrentHashSet<T>) private_asCollection(new ConcurrentHashSet<>(elements.size()), valueType, elements, force);
    }

    public static <T>ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, Iterable elements) {
        return toConcurrentHashSet(valueType, elements, null);
    }

    public static <T>ConcurrentHashSet<T> toConcurrentHashSet(C<T> valueType, Iterable elements, Force force) {
        if(elements == null || valueType == null) return new ConcurrentHashSet<>();
        return (ConcurrentHashSet<T>) private_asCollection(new ConcurrentHashSet<>(default_getIterableLength(elements)), valueType, elements, force);
    }

    @Note("ConcurrentSkipListSet")
    public static <T> ConcurrentSkipListSet<T> toConcurrentSkipListSet(Object array, C<T> valueType) {
        return toConcurrentSkipListSet(array, valueType, null, null);
    }

    public static <T> ConcurrentSkipListSet<T> toConcurrentSkipListSet(Object array, C<T> valueType, Force force) {
        return toConcurrentSkipListSet(array, valueType, null, force);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(Object array, C<T> valueType, Comparator<? super T> c) {
        return toConcurrentSkipListSet(array, valueType, c, null);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(Object array, C<T> valueType, Comparator<? super T> c, Force force) {
        if(array == null || !array.getClass().isArray() || valueType == null) return new ConcurrentSkipListSet<>(c);
        return (ConcurrentSkipListSet<T>) private_asCollection(new ConcurrentSkipListSet<>(c), valueType, array, Array.getLength(array), force);
    }


    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Object... elements) {
        return toConcurrentSkipListSet(valueType, null, null, elements);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Comparator<? super T> c, Object... elements) {
        return toConcurrentSkipListSet(valueType, c, null, elements);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Force force, Object... elements) {
        return toConcurrentSkipListSet(valueType, null, force, elements);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Comparator<? super T> c, Force force, Object... elements) {
        if(elements == null || valueType == null || elements.length == 0) return new ConcurrentSkipListSet<>(c);
        return (ConcurrentSkipListSet<T>) private_asCollection(new ConcurrentSkipListSet<>(c), valueType, elements, force);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Collection elements) {
        return toConcurrentSkipListSet(valueType, elements, null, null);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Collection elements, Comparator<? super T> c) {
        return toConcurrentSkipListSet(valueType, elements, c, null);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Collection elements, Force force) {
        return toConcurrentSkipListSet(valueType, elements, null, force);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Collection elements, Comparator<? super T> c, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new ConcurrentSkipListSet<>(c);
        return (ConcurrentSkipListSet<T>) private_asCollection(new ConcurrentSkipListSet<>(c), valueType, elements, force);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, OwnRows elements) {
        return toConcurrentSkipListSet(valueType, elements, null, null);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, OwnRows elements, Comparator<? super T> c) {
        return toConcurrentSkipListSet(valueType, elements, c, null);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, OwnRows elements, Force force) {
        return toConcurrentSkipListSet(valueType, elements, null, force);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, OwnRows elements, Comparator<? super T> c, Force force) {
        if(elements == null || elements.isEmpty() || valueType == null) return new ConcurrentSkipListSet<>(c);
        return (ConcurrentSkipListSet<T>) private_asCollection(new ConcurrentSkipListSet<>(c), valueType, elements, force);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Iterable elements) {
        return toConcurrentSkipListSet(valueType, elements, null, null);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Iterable elements, Comparator<? super T> c) {
        return toConcurrentSkipListSet(valueType, elements, c, null);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Iterable elements, Force force) {
        return toConcurrentSkipListSet(valueType, elements, null, force);
    }

    public static <T>ConcurrentSkipListSet<T> toConcurrentSkipListSet(C<T> valueType, Iterable elements, Comparator<? super T> c, Force force) {
        if(elements == null || valueType == null) return new ConcurrentSkipListSet<>(c);
        return (ConcurrentSkipListSet<T>) private_asCollection(new ConcurrentSkipListSet<>(c), valueType, elements, force);
    }
    /* ************************************************************************************************************
     *
     *          数组
     *
     * ************************************************************************************************************
     * */

    @Note("将源数组 sourceArray 里的数据转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(Object sourceArray, C<?> targetComponentType) {
        return toArray(sourceArray, targetComponentType, null);
    }

    @Note("将源数组 sourceArray 里的数据经过自定义处理后，转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(Object sourceArray, C<?> targetComponentType, Force force) {
        if(targetComponentType == null) throw new NullPointerException("目标数组的类型为 null");
        Class<?> mainType = targetComponentType.getMainType();
        if(sourceArray == null) return Array.newInstance(mainType, 0);
        Class<?> srcClass = sourceArray.getClass();
        if(!srcClass.isArray()) return Array.newInstance(mainType, 0);
        int length = Array.getLength(sourceArray);
        Object result = Array.newInstance(mainType, length);
        if(force == null) {
            if(mainType.isAssignableFrom(srcClass.getComponentType())) {
                System.arraycopy(sourceArray, 0, result, 0, length);
                return result;
            }
            for (int i = 0; i < length; i++) {
                Object o = Array.get(sourceArray, i);
                Array.set(result, i, ObjKit.toRealValue(o, targetComponentType));
            }
            return result;
        }
        for (int i = 0; i < length; i++) {
            Object o = Array.get(sourceArray, i);
            o = force.force(o);
            Array.set(result, i, ObjKit.toRealValue(o, targetComponentType));
        }
        return result;
    }

    @Note("将源数组 data 里的数据转换为指定类型的新数据，然后拷贝到新数组里返回。（该可变数组为了兼容不同类型的输入值）")
    public static Object toArray(C<?> targetComponentType, Object... data) {
        return toArray(targetComponentType, null, data);
    }

    @Note("将源数组 data 里的数据经过自定义处理后，转换为指定类型的新数据，然后拷贝到新数组里返回。（该可变数组为了兼容不同类型的输入值）")
    public static Object toArray(C<?> targetComponentType, Force force, Object... data) {
        if(targetComponentType == null) throw new NullPointerException("目标数组的类型为 null");
        Class<?> mainType = targetComponentType.getMainType();
        if(data == null) return Array.newInstance(mainType, 0);
        int length = data.length;
        if(length == 0) return Array.newInstance(mainType, 0);
        Object result = Array.newInstance(mainType, length);
        if(force == null) {
            for (int i = 0; i < length; i++) {
                Array.set(result, i, ObjKit.toRealValue(data[i], targetComponentType));
            }
            return result;
        }
        for (int i = 0; i < length; i++) {
            Object o = force.force(data[i]);
            Array.set(result, i, ObjKit.toRealValue(o, targetComponentType));
        }
        return result;
    }

    @Note("将源 Collection 集合里的数据转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(C<?> targetComponentType, Collection data) {
        return toArray(targetComponentType, data, null);
    }

    @Note("将源 Collection 集合里的数据经过自定义处理后，转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(C<?> targetComponentType, Collection data, Force force) {
        if(targetComponentType == null) throw new NullPointerException("目标数组的类型为 null");
        Class<?> mainType = targetComponentType.getMainType();
        if(data == null) return Array.newInstance(mainType, 0);
        int length = data.size();
        return private_asArray(length, data, targetComponentType, mainType, force);
    }

    @Note("将源自定义容器集合里的数据转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(C<?> targetComponentType, OwnRows data) {
        return toArray(targetComponentType, data, null);
    }

    @Note("将自定义容器集合里的数据经过自定义处理后，转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(C<?> targetComponentType, OwnRows data, Force force) {
        if(targetComponentType != null) {
            Class<?> mainType = targetComponentType.getMainType();
            if(data == null) return Array.newInstance(mainType, 0);
            int length = data.size();
            return private_asArray(length, data, targetComponentType, mainType, force);
        }
        throw new NullPointerException("目标数组的类型为 null");
    }

    @Note("将源其他可迭代容器7里的数据转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(C<?> targetComponentType, Iterable data) {
        return toArray(targetComponentType, data, null);
    }

    @Note("将其他可迭代容器里的数据经过自定义处理后，转换为指定类型的新数据，然后拷贝到新数组里返回")
    public static Object toArray(C<?> targetComponentType, Iterable data, Force force) {
        if(targetComponentType == null) throw new NullPointerException("目标数组的类型为 null");
        Class<?> mainType = targetComponentType.getMainType();
        if(data == null) return Array.newInstance(mainType, 0);
        int length = default_getIterableLength(data);
        return private_asArray(length, data, targetComponentType, mainType, force);
    }


    /* ************************************************************************************************************
     *
     *          拷贝
     *
     * ************************************************************************************************************
     * */

    @Note("将 srcArray 数组的元素拷贝到 tarArray 目标数组中")
    public static void copyTo(Object srcArray, Object tarArray) {
        copyTo(srcArray, tarArray, null, null);
    }

    @Note("将 srcArray 数组的元素转化为指定类型的新数据，然后拷贝到 tarArray 目标新数组中")
    public static void copyTo(Object srcArray, Object tarArray, C<?> tarComponentType) {
        copyTo(srcArray, tarArray, tarComponentType, null);
    }

    @Note("将 srcArray 数组的元素经过自定义处理后，转化为指定类型的新数据，然后拷贝到 tarArray 目标新数组中")
    public static void copyTo(Object srcArray, Object tarArray, C<?> tarComponentType, Force force) {
        if(srcArray == null || tarArray == null) return;
        Class<?> srcClass = srcArray.getClass();
        Class<?> tarClass = tarArray.getClass();
        if(!srcClass.isArray() || !tarClass.isArray()) return;
        int length = Math.min(Array.getLength(srcArray), Array.getLength(tarArray));
        if(length == 0) return;
        if(force == null) {
            if(tarClass.isAssignableFrom(srcClass)) {
                System.arraycopy(srcArray, 0, tarArray, 0, length);
                return;
            }
            C<?> c = tarComponentType;
            if(c == null) {
                c = C.getC(tarClass);
            }
            for (int i = 0; i < length; i++) {
                Object o = Array.get(srcArray, i);
                Array.set(tarArray, i, ObjKit.toRealValue(o, c));
            }
            return;
        }
        C<?> c = (tarComponentType != null) ? tarComponentType : C.getC(tarClass);
        for (int i = 0; i < length; i++) {
            Object o = Array.get(srcArray, i);
            o = force.force(o);
            Array.set(tarArray, i, ObjKit.toRealValue(o, c));
        }
    }

    @Note("将 srcArray 数组的元素拷贝到 target 目标 Collection 新集合中")
    public static void copyTo(Object srcArray, Collection target) {
        copyTo(srcArray, target, null, null);
    }

    @Note("将 srcArray 数组的元素转化为指定类型的新数据，然后拷贝到 target 目标 Collection 新集合中")
    public static void copyTo(Object srcArray, Collection target, C<?> targetComponentType) {
        copyTo(srcArray, target, targetComponentType, null);
    }

    @Note("将 srcArray 数组的元素经过自定义处理后，转化为指定类型的新数据，然后拷贝到 target 目标 Collection 新集合中")
    public static void copyTo(Object srcArray, Collection target, C<?> targetComponentType, Force force) {
        if(srcArray == null || target == null) return;
        Class<?> srcClass = srcArray.getClass();
        if(!srcClass.isArray()) return;
        int length = Array.getLength(srcArray);
        if(length == 0) return;
        C<?> c = targetComponentType;
        if(c == null) c = C.getC(srcClass);
        if(force == null) {
            for (int i = 0; i < length; i++) {
                Object o = Array.get(srcArray, i);
                target.add(ObjKit.toRealValue(o, c));
            }
            return;
        }
        for (int i = 0; i < length; i++) {
            Object o = Array.get(srcArray, i);
            o = force.force(o);
            target.add(ObjKit.toRealValue(o, c));
        }
    }

    @Note("将 srcArray 数组的元素拷贝到 target 目标新自定义容器集合中")
    public static void copyTo(Object srcArray, OwnRows target) {
        copyTo(srcArray, target, null, null);
    }

    @Note("将 srcArray 数组的元素转化为指定类型的新数据，然后拷贝到 target 目标新自定义容器集合中")
    public static void copyTo(Object srcArray, OwnRows target, C<?> targetComponentType) {
        copyTo(srcArray, target, targetComponentType, null);
    }

    @Note("将 srcArray 数组的元素经过自定义处理后，转化为指定类型的新数据，然后拷贝到 target 目标新自定义容器集合中")
    public static void copyTo(Object srcArray, OwnRows target, C<?> targetComponentType, Force force) {
        if(srcArray == null || target == null) return;
        Class<?> srcClass = srcArray.getClass();
        if(srcClass.isArray()) {
            C<?> c = targetComponentType;
            if(c == null) c = C.getC(srcClass);
            int length = Array.getLength(srcArray);
            if(length == 0) return;
            if(force == null) {
                for (int i = 0; i < length; i++) {
                    Object o = Array.get(srcArray, i);
                    target.add(ObjKit.toRealValue(o, c));
                }
            }
            else {
                for (int i = 0; i < length; i++) {
                    Object o = Array.get(srcArray, i);
                    o = force.force(o);
                    target.add(ObjKit.toRealValue(o, c));
                }
            }
        }
    }

    @Note("将可迭代容器的元素拷贝到 targetArray 目标数组中去")
    public static void copyTo(Iterable src, Object targetArray) {
        copyTo(src, targetArray, null, null);
    }

    @Note("将可迭代容器的元素转化为指定类型的新数据，然后拷贝到 targetArray 目标数组中去")
    public static void copyTo(Iterable src, Object targetArray, C<?> targetComponentType) {
        copyTo(src, targetArray, targetComponentType, null);
    }

    @Note("将可迭代容器的元素经过自定义处理后，转化为指定类型的新数据，然后拷贝到 targetArray 目标数组中去")
    public static void copyTo(Iterable src, Object targetArray, C<?> targetComponentType, Force force) {
        if(src == null) return;
        if(targetArray == null) return;
        Class<?> tarClass = targetArray.getClass();
        if(!tarClass.isArray()) return;
        int length = Array.getLength(targetArray);
        if(length == 0) return;
        Iterator iterator = src.iterator();
        if(!iterator.hasNext()) return;
        int index = 0;
        C<?> c = (targetComponentType == null) ? C.getC(tarClass) : targetComponentType;
        if(force == null) {
            while (iterator.hasNext()) {
                if(index == length) return;
                Array.set(targetArray, index, ObjKit.toRealValue(iterator.next(), c));
                index++;
            }
            return;
        }
        while (iterator.hasNext()) {
            if(index == length) return;
            Object o = iterator.next();
            o = force.force(o);
            Array.set(targetArray, index, ObjKit.toRealValue(o, c));
            index++;
        }
    }

    @Note("将可迭代容器的元素拷贝到 tar 目标 Collection 集合中去")
    public static void copyTo(Iterable src, Collection tar) {
        if(src == null || tar == null) return;
        if(src instanceof Collection) {
            tar.addAll((Collection) src);
            return;
        }
        for (Object o : src) tar.add(o);
    }

    @Note("将可迭代容器的元素转化为指定类型的新数据，然后拷贝到 tar 目标 Collection 集合中去")
    public static void copyTo(Iterable src, Collection tar, C<?> tarComponentType) {
        copyTo(src, tar, tarComponentType, null);
    }

    @Note("将可迭代容器的元素经过自定义处理后，转化为指定类型的新数据，然后拷贝到 tar 目标 Collection 集合中去")
    public static void copyTo(Iterable src, Collection tar, C<?> tarComponentType, Force force) {
        if(src == null || tar == null) return;
        if(force == null) {
            if(tarComponentType != null) {
                Iterator iterator = src.iterator();
                if(!iterator.hasNext()) return;
                while (iterator.hasNext()) {
                    tar.add(ObjKit.toRealValue(iterator.next(), tarComponentType));
                }
                return;
            }
            for (Object o : src) {
                tar.add(o);
            }
            return;
        }
        if(tarComponentType == null) {
            for (Object o : src) {
                tar.add(force.force(o));
            }
            return;
        }
        Iterator iterator = src.iterator();
        if(!iterator.hasNext()) return;
        while (iterator.hasNext()) {
            Object o = force.force(iterator.next());
            tar.add(ObjKit.toRealValue(o, tarComponentType));
        }
    }


    @Note("将可迭代容器的元素拷贝到 tar 目标自定义容器集合中去")
    public static void copyTo(Iterable src, OwnRows tar) {
        if(src == null || tar == null) return;
        tar.addAll(src);
    }

    @Note("将可迭代容器的元素转化为指定类型的新数据，然后拷贝到 tar 目标自定义容器集合中去")
    public static void copyTo(Iterable src, OwnRows tar, C<?> tarComponentType) {
        copyTo(src, tar, tarComponentType, null);
    }

    @Note("将可迭代容器的元素经过自定义处理后，转化为指定类型的新数据，然后拷贝到 tar 目标自定义容器集合中去")
    public static void copyTo(Iterable src, OwnRows tar, C<?> tarComponentType, Force force) {
        if(src == null || tar == null) return;
        if(force == null) {
            if(tarComponentType == null) {
                for (Object o : src) {
                    tar.add(o);
                }
                return;
            }
            Iterator iterator = src.iterator();
            if(!iterator.hasNext()) return;
            while (iterator.hasNext()) {
                tar.add(ObjKit.toRealValue(iterator.next(), tarComponentType));
            }
            return;
        }
        if(tarComponentType != null) {
            Iterator iterator = src.iterator();
            if(!iterator.hasNext()) return;
            while (iterator.hasNext()) {
                Object o = force.force(iterator.next());
                tar.add(ObjKit.toRealValue(o, tarComponentType));
            }
            return;
        }
        for (Object o : src) {
            tar.add(force.force(o));
        }
    }

    /* ************************************************************************************************************
     *
     *          反射
     *
     * ************************************************************************************************************
     * */

    @Note("通过反射构建指定长度的数组")
    public static Object buildArray(C<?> arrayType, int size) {
        Class<?> componentType = private_getArrayComponentType(arrayType);
        return Array.newInstance(componentType, size);
    }

    @Note("通过反射构建数组，然后将 Collection 集合的内容拷贝过去（拷贝时会尽可能做类型转换）")
    public static Object buildArray(C<?> arrayType, Collection cs) {
        Class<?> componentType = private_getArrayComponentType(arrayType);
        if(cs == null) return Array.newInstance(componentType, 0);
        int size = cs.size();
        if(size == 0) return Array.newInstance(componentType, 0);
        Object newArray = Array.newInstance(componentType, size);
        int index = 0;
        C<?> valueType = arrayType;
        if(!componentType.equals(arrayType.getMainType())) {
            valueType = C.getC(componentType);
            valueType.setDateFormatPattern(arrayType.getDateFormatPattern());
        }
        for (Object o : cs) {
            Array.set(newArray, index, ObjKit.toRealValue(o, valueType));
            index++;
        }
        return newArray;
    }


    @Note("通过反射构建数组，然后将自定义集合的内容拷贝过去（拷贝时会尽可能做类型转换）")
    public static Object buildArray(C<?> arrayType, OwnRows rows) {
        Class<?> componentType = private_getArrayComponentType(arrayType);
        if(rows == null) return Array.newInstance(componentType, 0);
        int size = rows.size();
        if(size != 0) {
            Object newArray = Array.newInstance(componentType, size);
            C<?> valueType = arrayType;
            if(!componentType.equals(arrayType.getMainType())) {
                valueType = C.getC(componentType);
                valueType.setDateFormatPattern(arrayType.getDateFormatPattern());
            }
            int index = 0;
            for (Object o : rows) {
                Array.set(newArray, index, ObjKit.toRealValue(o, valueType));
                index++;
            }
            return newArray;
        }
        return Array.newInstance(componentType, 0);
    }


    @Note("通过反射构建数组，然后将旧数组的内容拷贝过去（拷贝时会尽可能做类型转换）")
    public static Object buildArray(C<?> newArrayType, Object oldArray) {
        Class<?> componentType = private_getArrayComponentType(newArrayType);
        if(oldArray == null) return Array.newInstance(componentType, 0);
        Class<?> oldArrayClass = oldArray.getClass();
        if(oldArrayClass.isArray()) {
            int length = Array.getLength(oldArray);
            if(length == 0) return Array.newInstance(componentType, 0);
            Object result = Array.newInstance(componentType, length);
            C<?> valueType = newArrayType;
            if(!componentType.equals(newArrayType.getMainType())) {
                valueType = C.getC(componentType);
                valueType.setDateFormatPattern(newArrayType.getDateFormatPattern());
            }
            for (int i = 0; i < length; i++) {
                Object o = Array.get(oldArray, i);
                Object realValue = ObjKit.toRealValue(o, valueType);
                Array.set(result, i, realValue);
            }
            return result;
        }
        if(Collection.class.isAssignableFrom(oldArrayClass)) {
            return buildArray(newArrayType, (Collection) oldArray);
        }
        if(OwnRows.class.isAssignableFrom(oldArrayClass)) {
            return buildArray(newArrayType, (OwnRows) oldArray);
        }
        return Array.newInstance(componentType, 0);
    }


    @Note("通过反射构建数组，然后将可迭代容器中的内容拷贝过去（拷贝时会尽可能做类型转换）")
    public static Object buildArray(C<?> newArrayType, Iterable element) {
        if(element instanceof Collection) return buildArray(newArrayType, (Collection) element);
        if(element instanceof OwnRows) return buildArray(newArrayType, (OwnRows) element);
        Class<?> componentType = private_getArrayComponentType(newArrayType);
        if(element == null) return Array.newInstance(componentType, 0);
        int length = default_getIterableLength(element);
        if(length == 0) return Array.newInstance(componentType, 0);
        Object newArray = Array.newInstance(componentType, length);
        int index = 0;
        Class<?> mainType = newArrayType.getMainType();
        C<?> valueType = newArrayType;
        if(!componentType.equals(mainType)) {
            valueType = C.getC(componentType);
            valueType.setDateFormatPattern(newArrayType.getDateFormatPattern());
        }
        for (Object o : element) {
            Array.set(newArray, index, ObjKit.toRealValue(o, valueType));
            index++;
        }
        return newArray;
    }


    @Note("通过反射构建自定义集合，并设置初始容量为 initSize")
    public static OwnRows buildRow(C<?> rowType, int initSize) {
        return private_buildRow(rowType, Math.min(initSize, 0));
    }

    @Note("通过反射构建自定义集合，并将 Collection 集合的内容拷贝过去（拷贝时会尽可能做类型转换）")
    public static OwnRows buildRow(C<?> rowType, Collection cs) {
        OwnRows result = private_buildRow(rowType, cs.size());
        C<?> componentType = rowType.generic(0);
        if(componentType == null) {
            result.addAll(cs);
            return result;
        }
        for(Object o : cs) {
            Object realValue = ObjKit.toRealValue(o, componentType);
            result.add(realValue);
        }
        return result;
    }


    @Note("通过反射构建自定义集合，并将自定义集合的内容拷贝过去（拷贝时会尽可能做类型转换）")
    public static OwnRows buildRow(C<?> rowType, OwnRows row) {
        OwnRows result = private_buildRow(rowType, row.size());
        C<?> componentType = rowType.generic(0);
        if(componentType != null) {
            for(Object o : row) {
                Object realValue = ObjKit.toRealValue(o, componentType);
                result.add(realValue);
            }
            return result;
        }
        result.addAll(row);
        return result;
    }


    @Note("通过反射构建自定义集合，并将数组的内容拷贝过去（拷贝时会尽可能做类型转换）")
    public static OwnRows buildRow(C<?> rowType, Object array) {
        if(array == null || !array.getClass().isArray()) {
            return private_buildRow(rowType, 0);
        }
        int length = Array.getLength(array);
        OwnRows result = private_buildRow(rowType, length);
        C<?> componentType = rowType.generic(0);
        if(componentType != null) {
            for (int i = 0; i < length; i++) {
                Object o = Array.get(array, i);
                result.add(ObjKit.toRealValue(o, componentType));
            }
            return result;
        }
        for (int i = 0; i < length; i++) {
            result.add(Array.get(array, i));
        }
        return result;
    }


    /* ************************************************************************************************************
     *
     *          私有逻辑
     *
     * ************************************************************************************************************
     * */



    @Note("计算哈希表合适的初始化容量值，以达到最小次数的扩容")
    static int default_calcSize(int srcLength) {
        int newSize = (int) (srcLength / 0.75f + 1.0f);
        return Math.min(newSize, MapEnum.MAX_SIZE);
    }


    @Note("获取可迭代容器的容量")
    static int default_getIterableLength(Iterable iterable) {
        int length = 0;
        for (Object o : iterable) {
            length++;
        }
        return length;
    }

    @Note("将数组的元素拷贝到 Collection 集合里")
    private static <T>Collection<T> private_asCollection(Collection<T> result, C<T> valueType, Object array, int length, Force force) {
        if(force == null) {
            for (int i = 0; i < length; i++) {
                Object o = Array.get(array, i);
                result.add((T) ObjKit.toRealValue(o, valueType));
            }
            return result;
        }
        for (int i = 0; i < length; i++) {
            Object o = force.force(Array.get(array, i));
            result.add((T) ObjKit.toRealValue(o, valueType));
        }
        return result;
    }

    @Note("将数组的元素拷贝到 Collection 集合里")
    private static <T>Collection<T> private_asCollection(Collection<T> result, C<T> valueType, Object[] elements, Force force) {
        if(force == null) {
            for (Object o : elements) {
                result.add((T) ObjKit.toRealValue(o, valueType));
            }
            return result;
        }
        for (Object o : elements) {
            o = force.force(o);
            result.add((T) ObjKit.toRealValue(o, valueType));
        }
        return result;
    }

    @Note("将可迭代容器里的元素拷贝到 Collection 集合里")
    private static <T>Collection<T> private_asCollection(Collection<T> result, C<T> valueType, Iterable elements, Force force) {
        if(force == null) {
            for (Object o : elements) {
                result.add((T) ObjKit.toRealValue(o, valueType));
            }
        }
        else {
            for (Object o : elements) {
                o = force.force(o);
                result.add((T) ObjKit.toRealValue(o, valueType));
            }
        }
        return result;
    }

    @Note("将可迭代容器的数据拷贝到新数组里返回")
    private static Object private_asArray(int length, Iterable data, C<?> targetComponentType, Class<?> mainType, Force force) {
        if(length == 0) return Array.newInstance(mainType, 0);
        Object result = Array.newInstance(mainType, length);
        int index = 0;
        if(force == null) {
            for (Object o : data) {
                if(index == length) return result;
                Array.set(result, index, ObjKit.toRealValue(o, targetComponentType));
                index++;
            }
            return result;
        }
        for (Object o : data) {
            if(index == length) return result;
            o = force.force(o);
            Array.set(result, index, ObjKit.toRealValue(o, targetComponentType));
            index++;
        }
        return result;
    }


    @Note("根据 JavaBean 类型包装对象获取其中真正的用于构建数组的类型/泛型")
    private static Class<?> private_getArrayComponentType(C<?> c) {
        Class<?> mainType = c.getMainType();
        if(mainType.isArray()) {
            return mainType.getComponentType();
        }
        if(Collection.class.isAssignableFrom(mainType) ||
                OwnRows.class.isAssignableFrom(mainType)) {
            return c.hasGenericType()
                    ? c.generic(0).getMainType()
                    : Object.class;
        }
        return mainType;
    }


    @Note("通过类型包装对象构建一个自定义容器对象")
    private static OwnRows private_buildRow(C<?> rowType, int size) {
        Class<?> mainType = rowType.getMainType();
        if(OwnRows.class.equals(mainType) || AbsOwnList.class.equals(mainType) || OwnList.class.equals(mainType)) {
            if(rowType.argCount() == 0) {
                return new OwnList<>(MapEnum.calcInitSize(size));
            }
            C<OwnList> newC = new C<OwnList>() {};
            rowType.copyTo(newC);
            return ObjKit.buildObject(newC);
        }
        if(AbsOwnSet.class.equals(mainType) || OwnSet.class.equals(mainType)) {
            if(rowType.argCount() == 0) {
                return new OwnSet<>(MapEnum.calcInitSize(size));
            }
            C<OwnSet> newC = new C<OwnSet>() {};
            rowType.copyTo(newC);
            return ObjKit.buildObject(newC);
        }
        return (OwnRows) ObjKit.buildObject(rowType);
    }
}
